﻿#include "OperatorsSave.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKAppFramework/FITKComponents.h"
#include "FITK_Kernel/FITKAppFramework/FITKRunTimeSetting.h" 
#include "FITK_Kernel/FITKAppFramework/FITKAppSettings.h"
#include "FITK_Kernel/FITKAppFramework/FITKMessage.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
#include "FITK_Kernel/FITKCore/FITKActionOperator.h"
#include <QFileDialog>

namespace ModelOper
{
    OperatorsSave::OperatorsSave()
    {

    }

    OperatorsSave::~OperatorsSave()
    {

    }

    bool OperatorsSave::execGUI()
    {
        Core::FITKActionOperator* actoper = Core::FITKOperatorRepo::getInstance()->
            getOperatorT<Core::FITKActionOperator>("actionSaveAs");
        if (actoper == nullptr) return false;
        actoper->setEmitter(_emitter);
        //从运行设置中获取保存的文件
        AppFrame::FITKRunTimeSetting* rs = FITKAPP->getGlobalData()->getRunTimeSetting();
        if (rs)
        {
            QString file = rs->getValueT<QString>("ProjectFile");
            if (QFile::exists(file))
            {
                //已经保存的文件直接覆盖写出
                actoper->setArgs("FileName", file);
                actoper->execProfession();
                return false;
            }
            else
            {
                //文件不存在则弹出选取对话框
                actoper->actionTriggered();
                return false;
            }
        }

        
    }

    bool OperatorsSave::execProfession()
    {
        return true;
    }

    void OperatorsSave::ioThreadFinishedSlot()
    {
    }
}

